home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / amos / amoslist-0295.lzh / AMOSLIST / text0012.txt < prev    next >
Encoding:
Text File  |  1995-03-01  |  3.7 KB  |  114 lines

  1. > > And a general question about coding:
  2. > > 
  3. > > What is a good procedure for detecting a "tap" of a fire button and a 
  4. > > "press" (button held down)? - Carl Chavez
  5. > > 
  6.  
  7. > PROCEDURE TESTHOLDBUTTON[STICK]
  8. >    Shared LAST_TIME,START_TIME
  9. >    If Fire(STICK) 
  10. >       If LAST_TIME
  11. >      'Button is still held from previous call
  12. >         Pop Proc[-1]
  13. >       Else
  14. >      If START_TIME=0
  15. >         'Beginning of a new press
  16. >         START_TIME=Timer
  17. >         Pop Proc[0]
  18. >      Else
  19. >         'Button pressed in a previous call, but
  20. >         'timeout for a tap has not expired yet
  21. >         If Timer-STARTTIME<2000
  22. >            'Cant decide which it is yet
  23. >            Pop Proc[0]
  24. >         Else
  25. >            'Decided it is a press
  26. >         LAST_TIME=True
  27. >         Pop Proc[-1]
  28. >         End If
  29. >      End If
  30. >       End If
  31. >    Else
  32. >       'Button not pressed.
  33. >       If LAST_TIME
  34. >      'Just released from a press.
  35. >      LAST_TIME=False
  36. >      START_TIME=0
  37. >      Pop Proc[0]
  38. >       Else
  39. >      If START_TIME
  40. >         'Was a tap
  41. >         START_TIME=0
  42. >         Pop Proc[1]
  43. >      Else
  44. >         'Button Never Pressed at all.
  45. >         Pop Proc[0]
  46. >      End If
  47. >       End If
  48. >    End If
  49. > End Proc
  50. >     
  51. > This returns:
  52. >     0 = Nothing as happend / the fire button is pressed, but not
  53. >         enough time has passed to tell if it is a tap or press
  54. >     1 = A tap has occured
  55. >     -1 = A press has occured.
  56. > It also has that advantage that it doesn't wait in the procedure for
  57. > 2000 50ths of a second, but exits immediately.As long as you call it
  58. > regularly, there won't be a problem, but if you leave it too long
  59. > between calls it might think taps are presses.
  60. > Note - I haven't tested this - I don't have an amiga handy.
  61. > - PAUL HICKMAN
  62.  
  63. I tried out this routine last night and with some small modifications it worked.
  64. The logic was spot on, just some syntax and spelling problems.
  65.  
  66. I couldn't get the "pop proc[1]" type statement working nor could I find
  67. reference to using pop proc in this manner. Please enlighten me if this 
  68. is possible.  I simply used:
  69.  
  70. ; button declared as global
  71.       button=1      
  72.       pop proc
  73.  
  74. I think I had problems with the START_TIME variable name as it clashed with a 
  75. reserved word so I just used BEGIN_TIME.
  76.  
  77. Where Paul used "If START_TIME" I used "If BEGIN_TIME<>0".
  78. Are these If's testing the same thing? (notwithstanding my change of variable name)
  79.  
  80. I would also like to test for the joystick being held or pressed to the left or right
  81. or just tapped as well as the button being tested in this manner. Later I will probably
  82. want to do the same for up and down!
  83.  
  84. Q1. Should I incorporate all of this in the one procedure which checks every feature of
  85.     the joystick in one test of the joy(1) function or should I write seperate procedures.
  86.  
  87. Q2. I am just playing around with writing a program to move a car (bob that is) around on 
  88.      the screen eventually with the ability to make 15 degree turns in an overhead perspective.
  89.      The controls would be something like : press and hold fire button to accelerate
  90.      press left to turn anticlockwise by 15 degrees and right to turn clockwise 15 deg.
  91.  
  92.      The car is moving around the screen but is a little (well, a lot) erratic and the feel
  93.      is just not there.
  94.       
  95.      Has anybody out there written a car racing game that would give me some clues or code
  96.      or logic for handling the "mechanics" of steering a car around.
  97.  
  98.  Q3. I seem to recall the Skidmarks game documentation referring to using BSpline quadratics
  99.      for the movement of the cars around corners. Does anybody know anything about that?
  100.      I seem to recall that they even supplied some of the assembler code they used. Yes I
  101.      know it was written in Blitz Basic but they also used calls to assembler code. 
  102.  
  103. Thanks ,
  104. Max Monahan
  105. M.Monahan@bom.gov.au
  106.       
  107.  
  108.